<template>
    <div class="det-comment">
        <p class="det-com-p">评论 ({{ props.commdata.length }})</p>
        <div class="det-body" v-for="item in props.commdata" :key="item._id">
            <div class="det-com-box">
                <div class="det-com-left">
                    <img src="@/assets/logo.png" alt="" />
                </div>
                <div class="det-com-right">
                    <p class="det-com-r-m">{{ item.name }}</p>
                    <p class="det-com-r-t">{{ item.text }}</p>
                    <ul class="det-com-r-uls">
                        <li>{{ dayjs(item.timer)
                            .format('YYYY-MM-DD HH:mm') }}</li>
                        <li class="det-com-lis">
                            <span><van-icon name="good-job-o" size="16" />&nbsp;{{ item.likenum }}</span>&nbsp;&nbsp;
                            <span @click="adds(item)"><van-icon name="chat-o" size="16" />&nbsp;{{ item.children?.length
                                || 0 }}</span>
                            <span v-if="item.user">
                                <span v-if="item.user.uid === users.uid">&nbsp;
                                    <van-popover v-model:show="showPopover" :actions="actions" @select="onfudel(item)" placement="left" >
                                        <template #reference>
                                            <van-icon name="ellipsis" />
                                        </template>
                                    </van-popover>
                                </span>
                            </span>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="det-com-box-fu" v-for="itm in item.children" :key="itm._id">
                <div class="det-com-left">
                    <img src="@/assets/logo.png" alt="" />
                </div>
                <div class="det-com-right">
                    <p class="det-com-r-m">{{ itm.name }}</p>
                    <p class="det-com-r-t">{{ itm.text }}</p>
                    <ul class="det-com-r-uls">
                        <li>{{ dayjs(itm.timer)
                            .format('YYYY-MM-DD HH:mm') }}</li>
                        <li class="det-com-lis">
                            <span><van-icon name="good-job-o" size="16" />&nbsp;{{ itm.likenum }}</span>&nbsp;&nbsp;
                            <span @click="adds(item)"><van-icon name="chat-o" size="16" />&nbsp;{{ itm.children?.length
                                || 0 }}</span>
                             <span v-if="itm.user">
                                <span v-if="itm.user.uid === users.uid">&nbsp;
                                    <van-popover v-model:show="showPopover1" :actions="actions" @select="onzidel(itm)" placement="left" >
                                        <template #reference>
                                            <van-icon name="ellipsis" />
                                        </template>
                                    </van-popover>
                                </span>
                            </span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import dayjs from 'dayjs';
// import Axios from '@/utils/index.js'

const props = defineProps({
    commdata: {
        type: Array,
        required: true
    }
})
const emits = defineEmits(['additem','onfudel','onzidel']);
const adds = (item) => {
    emits('additem', item)
}

const users = ref({ name: 'qwe', uid: '1712904244093' })
const showPopover = ref(false);
const actions = [
      { text: '删除' },
      { text: '选项二' },
      { text: '选项三' },
    ];
const onfudel = (dx) => {
    emits('onfudel', dx)
};
const showPopover1 = ref(false);
const onzidel = (dx) => {
    emits('onzidel', dx)
}
</script>

<style lang="scss" scoped>
.det-comment {
    .det-com-p {
        color: #999999;
        font-size: 14px;
        margin: 10px 0;
    }

    .det-com-box {
        display: flex;
        justify-content: space-between;
        margin: 10px 0;

        .det-com-left {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: bisque;

            img {
                height: 40px;
                width: 40px;
                border-radius: 50%;
            }
        }

        .det-com-right {
            width: 300px;
            height: 70px;

            /* background-color: aquamarine; */
            .det-com-r-m {
                font-size: 14px;
            }

            .det-com-r-t {
                font-size: 14px;
                padding: 5px 0;
            }

            .det-com-r-uls {
                font-size: 12px;
                color: #999999;
                display: flex;
                justify-content: space-between;

                li {
                    line-height: 20px;
                    align-items: center;
                    vertical-align: middle;
                }
            }
        }
    }

    .det-com-box-fu {
        display: flex;
        justify-content: space-between;
        margin: 10px 50px 0;
        width: 300px;

        .det-com-left {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: bisque;

            img {
                height: 40px;
                width: 40px;
                border-radius: 50%;
            }
        }

        .det-com-right {
            width: 250px;
            height: 70px;

            /* background-color: aquamarine; */
            .det-com-r-m {
                font-size: 14px;
            }

            .det-com-r-t {
                font-size: 14px;
                padding: 5px 0;
            }

            .det-com-r-uls {
                font-size: 12px;
                color: #999999;
                display: flex;
                justify-content: space-between;

                li {
                    line-height: 20px;
                    align-items: center;
                    vertical-align: middle;
                }
            }
        }
    }
}
</style>